package com.huang.eduorder.component;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class MqConfig {

    // ttl 交换机与队列  五消费者与其绑定
    @Bean
    public Queue ttlqueue(){
        Map<String, Object> map = new HashMap<>();
        map.put("x-message-ttl",10000);//
      map.put("x-dead-letter-exchange","canalExchange");
      map.put("x-dead-letter-routing-key","canalOrderKey");
        return new Queue("ttlqueue",true,false,false,map);
    }
    @Bean
    public TopicExchange noExchagne(){return new TopicExchange("noExchange",true,false);}
    @Bean
    public Binding noBind(){
        return BindingBuilder.bind(ttlqueue()).to(noExchagne()).with("nokey");
    }

    // 订单取消 队列与交换机
    @Bean
    public TopicExchange canalExchange(){
        return new TopicExchange("canalExchange",true,false);
    }
    @Bean
    public Queue canalQueue(){
        return new Queue("canalQueue",true);
    }
    @Bean
    public Binding canalBind(){
        return BindingBuilder.bind(canalQueue()).to(canalExchange()).with("canalOrderKey");
    }


    // 订单 消息 队列与交换机
    @Bean
    public Queue orderQ(){return  new Queue("orderQueue",true);}
    @Bean
    public TopicExchange orderExchange(){
        return new TopicExchange("orderExchange",true,false);
    }
    @Bean
    public Binding orderBind(){
        return BindingBuilder.bind(orderQ()).to(orderExchange()).with("normalkey");
    }


}
